// RMSClientSocket.h: interface for the CRMSClientSocket class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_RMSCLIENTSOCKET_H__B2CBBF15_FD1E_44CC_A59D_F06B9675FBB4__INCLUDED_)
#define AFX_RMSCLIENTSOCKET_H__B2CBBF15_FD1E_44CC_A59D_F06B9675FBB4__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef _RMS_TRANSLATOR_
#if defined(_OEM_) && defined(_TEC_)
#include "../Common/SNGlog.h"
#endif //defined(_OEM_) && defined(_TEC_)
#endif //ndef _RMS_TRANSLATOR_

#include "../Common/RMSThread.h"
#include "../Common/CBitrateShape.h"
class CBaseServer;
class CRMSClientSocket : public CRMSThread  
{
public:
	CRMSClientSocket::CRMSClientSocket(CBaseServer*);
	virtual ~CRMSClientSocket();

#ifndef _RMS_TRANSLATOR_
#if defined(_OEM_) && defined(_TEC_)
	SNGLOG clientLog;
	char RingStringCopy[1000];
#endif //defined(_OEM_) && defined(_TEC_)
#endif //ndef _RMS_TRANSLATOR_

#if defined(_RMS_TRANSLATOR_) && defined(_JNC_REC_)
	BOOL parseDateTime(CString& str, TimeMark& t);
	TimeMark* getRecords(int nCameraID, TimeMark& from, TimeMark& to, int& nfiles);
#endif //defined(_RMS_TRANSLATOR_) && defined(_JNC_REC_)

#ifndef _CYCLIC_BUFFER_
	BOOL getStartPosition(FILE* f);
#endif //ndef _CYCLIC_BUFFER_

	int				 CameraID;
	DWORD			 lastSendSize;
	DWORD			 lastSendTime;
	/*
	int				 *pSzVideo;// pointer to size of video
	BYTE			 *dtVideo;// pointer to video data
	int				 *pSzDate;// pointer to size of date
	BYTE			 *dtDate;// pointer to date
	int				 *pSzTime;// pointer to size of time
	BYTE			 *dtTime;// pointer to time
	CRITICAL_SECTION *pCriticalData;// pointer to critical section
	*/
	CBaseServer *pBaseServer;
// Members
	SOCKET m_clientSocket;
	SOCKADDR_IN m_saServer;
	SOCKADDR_IN m_saClient;

	BYTE	m_byID;

	BYTE*	m_pData;
	char	m_szIP[50];

	bool	m_bActive;
	bool	NewPassword;
	char    RingString[1000];
	int		RingStatus;

	CBitrateShape bitrateShaper;

// Methods
	void OnCriticalTerminate();
	void EnableNoVideo(BOOL bEnable);

	void setCallStatus(short status);

protected:
	DWORD ThreadFunc();

	BOOL GetClientRequest();
private:
	fpos_t m_lBeginPosition;
	fpos_t m_lEndPosition;
	FILE* m_file;
	BOOL m_bTimeMark;
	BOOL m_bTimeMark1;
	BOOL m_bVideo;
	BOOL m_bAudio;
	BOOL m_bTime;
	BOOL m_bDate;

	DWORD m_dwTypeTimeMark;
	DWORD m_dwTypeVideo;
	DWORD m_dwTypeAudio;
	DWORD m_dwTypeTime;
	DWORD m_dwTypeDate;

	BOOL m_bStored;
	BOOL m_bSupportRing;
	TimeMark m_timeStart;
	TimeMark m_timeEnd;
	TimeMark m_timeFrom;
	TimeMark m_timeTo;

	fpos_t m_lFindTotal;

	BOOL m_bNoVideoEnabled;
    int NoVideo;

#ifdef _CYCLIC_BUFFER_
	CString m_strBeginFile;
	CString m_strEndFile;
#endif

	BOOL	FindFrame(FILE* f, int nDirect);
	BOOL	TimeCompare(FILE* f, TimeMark& tm, int& result);
	DWORD	GetFrameLength(FILE* f);
	void	ResetData();
	int SendData(int Socket, void* Data,int nLen,int* Terminate);
	void finish();
	DWORD   Caller[1024];

#if defined(_RMS_TRANSLATOR_) && defined(_JNC_REC_)
	BOOL m_bGetRecords;
#endif //defined(_RMS_TRANSLATOR_) && defined(_JNC_REC_)
#ifdef _IPR_
	BOOL	IsRegistedIP(in_addr sin_addr);
#endif //def _IPR_
};

typedef CRMSClientSocket* LPRMSClientSocket;

#endif // !defined(AFX_RMSCLIENTSOCKET_H__B2CBBF15_FD1E_44CC_A59D_F06B9675FBB4__INCLUDED_)
